package star.搜索与回溯.搜索树第K大节点;

public class KthLargest {
    int k,res;
    public int kthLargest(TreeNode root, int k) {
        this.k = k;
        dfs(root);
        return res;
    }

    void dfs(TreeNode node){
        if (node==null) return;
        dfs(node.right);
        if (--k==0) res =  node.val;
        dfs(node.left);
    }
/*    int res, k;
    public int kthLargest(TreeNode root, int k) {
        this.k = k;
        dfs(root);
        return res;
    }
    void dfs(TreeNode root) {
        if(root == null) return;
        dfs(root.right);
        if(k == 0) return;
        if(--k == 0) res = root.val;
        dfs(root.left);
    }*/
}
